package de.fanda.hib.data;

import java.util.ArrayList;
import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.OneToMany;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

@Entity(name = "users")
@Table(name = "user")
public class User
{

	@Id
	@Column(name = "id")
	private int		id;

	@Column(name = "firstname")
	private String	firstName;

	@Column(name = "lastname")
	private String	lastName;
	
	@Column(name = "age")
	private int		age;
	
	@OneToMany(fetch = FetchType.LAZY, mappedBy = "user")
	private List<Language> lanuages = new ArrayList<Language>();
	
	@ManyToMany
	@JoinTable(name="user_account",
			   joinColumns={@JoinColumn(name="user_id")},
			   inverseJoinColumns = {@JoinColumn(name="account_id")})
	private List<Account> accounts = new ArrayList<Account>();

	public User(int id, String firstName, String lastName, int age)
	{
		this.id = id;
		this.firstName = firstName;
		this.lastName = lastName;
		this.age = age;
	}

	public User(String firstName, String lastName, int age)
	{
		this.firstName = firstName;
		this.lastName = lastName;
		this.age = age;
	}

	public User()
	{
	}

	public int getId()
	{
		return id;
	}

	public void setId(int id)
	{
		this.id = id;
	}

	public String getFirstName()
	{
		return firstName;
	}

	public void setFirstName(String firstName)
	{
		this.firstName = firstName;
	}

	public String getLastName()
	{
		return lastName;
	}

	public void setLastName(String lastName)
	{
		this.lastName = lastName;
	}

	public int getAge()
	{
		return age;
	}

	public void setAge(int age)
	{
		this.age = age;
	}
	
	
	public List<Language> getLanuages()
	{
		return lanuages;
	}

	public void setLanuages(List<Language> lanuages)
	{
		this.lanuages = lanuages;
	}
	

	public List<Account> getAccounts()
	{
		return accounts;
	}

	public void setAccounts(List<Account> accounts)
	{
		this.accounts = accounts;
	}

	@Override
	public String toString()
	{
		String res = "";

		res += "User = " + id + "," + firstName + ", " + lastName + ", age=" + age;

		return res;
	}

}
